﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAOTAgency;

namespace ManageTours
{
    public partial class ViewToursEditHotelFacilties : Form
    {
        public int TourId { get; set; }
        public List<int> hotelFacilitiesIds;

        public ViewToursEditHotelFacilties()
        {
            InitializeComponent();
        }

        private void ViewToursEditHotelFacilties_Load(object sender, EventArgs e)
        {
            hotelFacilitiesIds = new List<int>();
            IQueryable<int> hf = DAO.GetHotelFacilitiesByTourId(this.TourId);
            foreach (var item in DAO.GetAllHotelFacilities())
            {
                if (hf.Contains(item.HotelFacilitiesID))
                {
                    checkedListBoxHotelFacilties.Items.Add(item,true);
                    hotelFacilitiesIds.Add(item.HotelFacilitiesID);
                }
                else
                {
                    checkedListBoxHotelFacilties.Items.Add(item,false);
                }
            }
            
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            DAO.DeleteHotelFacilitiesToursRelations(this.TourId, this.hotelFacilitiesIds);
            var selected = checkedListBoxHotelFacilties.CheckedItems;
            List<int> selectedItems = new List<int>();
            foreach (HotelFacility item in selected)
	        {
		        selectedItems.Add(item.HotelFacilitiesID);
	        }
            DAO.AddHotelFacilitiesToursRelations(this.TourId, selectedItems);
            this.Close();
        }
    }
}
